package game;

import math.EulerAngles;

import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;

import sys.SysParam;
import world.Camera;
import world.WorldManager;

public class CameraUpdater {
	public static void update(){
		Camera camera = WorldManager.get().getCamera();
		Float rotateDistance = SysParam.MOUSE_SPEED;

		float mouseDX = Mouse.getDX();
		float mouseDY = Mouse.getDY();
		if (mouseDX != 0 && mouseDY != 0) {
			EulerAngles rotatedAngles = new EulerAngles(mouseDX * rotateDistance, mouseDY * rotateDistance, 0.0f);
			camera.rotate(rotatedAngles);
		}

		Float moveDistance = SysParam.MOVEMENT_SPEED;
		if (Keyboard.isKeyDown(Keyboard.KEY_W)) {
			camera.moveForward(moveDistance);
		} else if (Keyboard.isKeyDown(Keyboard.KEY_S)) {
			camera.moveBackwards(moveDistance);
		} else if (Keyboard.isKeyDown(Keyboard.KEY_A)) {
			camera.moveLeft(moveDistance);
		} else if (Keyboard.isKeyDown(Keyboard.KEY_D)) {
			camera.moveRight(moveDistance);
		} else if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) {
			camera.moveUp(moveDistance);
		} else if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
			camera.moveDown(moveDistance);
		}

		if (Keyboard.isKeyDown(Keyboard.KEY_I)) {
			camera.pitch(-moveDistance);
		} else if (Keyboard.isKeyDown(Keyboard.KEY_K)) {
			camera.pitch(moveDistance);
		} else if (Keyboard.isKeyDown(Keyboard.KEY_J)) {
			camera.heading(moveDistance);
		} else if (Keyboard.isKeyDown(Keyboard.KEY_L)) {
			camera.heading(-moveDistance);
		} 
	}
}
